
var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}

$(function() {  
	queryPrdFeeYieldList();//默认查询非标准化估值
});

/**
 * 非标准化估值
 */
var $prdFeeYieldList = $("#prdFeeYieldList");
function queryPrdFeeYieldList(){
	/**
	 * 产品费用与收益展示列表
	 **/
	$prdFeeYieldList.jqGrid({
        url: PATH_PREFIX+'prdFeeYieldListPage.do',
        //caption: '产品费用与收益列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',
        datatype: "json",
        colNames:["","子产品编号",'',"产品名称","产品代码", "所属部门", "项目经理", "份额", "基金代码","预付金额","实付金额","操作"],        
		colModel:[
			        {name:'fyId',index:'fyId',align:'left',width: 40, hidden:true,key:true,sortable:false},
					{name:'subPrdCode',index:'subPrdCode',align:'left',width: 40, hidden:true,sortable:false},
					{name:'prjCode',index:'prjCode',align:'left',width: 40, hidden:true,sortable:false},
                    {name:'prjsName',index:'prjsName',align:'left',width: 40, hidden:false,sortable:false,formatter:showTitle},
                    {name:'outCode',index:'outCode',align:'left',width: 40, hidden:false, resizable:true,sortable:false},
                    {name:'departName',index:'departName',align:'left',width: 40, hidden:true, resizable:true,sortable:false},
					{name:'managerName',index:'managerName',align:'left',width: 40, hidden:true, resizable:true,sortable:false}, 
					{name:'subFundsName',index:'subFundsName',align:'left', width: 20, hidden:false, resizable:true, sortable:false},
					{name:'fundCode',index:'fundCode',align:'left', width: 40, hidden:false, resizable:true, sortable:false},
					{name:'expectPayAmount',index:'expectPayAmount',align:'left', width: 40, hidden:false, resizable:true, sortable:false},
					{name:'bnsAmt',index:'bnsAmt',align:'left', width: 40, hidden:false, resizable:true, sortable:false},
		            {name:'option', index:'option', width: 20, resizable: true, sortable: false }
				],     
        rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },
        postData:{
        	'sp[prjsName]':'',
        	'sp[outCode]':'',
        	'sp[subFundsName]':'',
        	'sp[fundCode]':'',
        	'sp[feeName]':'',
	    	'sp[expectPayDateBegin]':'',
	    	'sp[expectPayDateEnd]':'',
	    	'sp[bnsDateBegin]':'',
	    	'sp[bnsDateEnd]':'',
		 	'sp[feeType]': '',
		 	'sp[isPay]':'',
	    	'sp[deptId]':'',
	        'sp[mgrId]':''
		},
        multiselect: false,
        pager: "#prdFeeYieldPage",
        hidegrid: false,
        datatype:'local',
        gridComplete: function(){
        	var ids = $prdFeeYieldList.jqGrid('getDataIDs');
			for (var i = 0; i < ids.length; i++) {
                var id = ids[i];
                var rowData = $prdFeeYieldList.jqGrid('getRowData', id);
                var subPrdCode = rowData.subPrdCode;
                var subFundsName = rowData.subFundsName;
//	            var addBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="新增" onclick="addFeeOrYield(\''+subPrdCode+ '\',\''
//				+ subFundsName
//				+'\');">新增</a>';
	            //var downloadBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="下载" disabled>下载</a>';
	            
	            //downloadBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="下载" onclick="WASP_PRD_TEMPLATE.download(\''+templateId+'\');">下载</a>';
	            
	            var params = {
						'addData'    : 	'addDataTemp'
					};
					
				var permissionButton = Permission_Button.configPermissionButton(params);
				
				permissionButton.addData = Permission_Button.clickPermissionButton('addDataTemp','addFeeOrYield(\''+subPrdCode+ '\',\''+ subFundsName+'\');');
				
	            $prdFeeYieldList.jqGrid('setRowData', ids[i], { option: Permission_Button.linkAllBtn(permissionButton)});
			}
		},
		subGrid: true,
		subGridRowExpanded: subGridRowExpanded,
		subGridRowColapsed: function(subgrid_id, row_id) {
			$("#subGridTBId").val("");
		}
	}); 

	$prdFeeYieldList.navGrid('#prdFeeYieldPage', { edit: false, add: false, del: false, search: false, refreshstate: 'current' });
	$prdFeeYieldList.jqGrid('setFrozenColumns');
    jqGridResize($("#prdFeeYieldList"));
    
    $prdFeeYieldList.jqGrid('setGridParam',{datatype:'json'});//初始的时候不查询
	json?queryByCondtionForCustomerEquity(json):queryByCondtion(true);//判断是否来自总览
}

//导出
function exportToExcel(){
	var prjsName = $.trim($("#q-prjsName").val());
	var outCode = $.trim($("#q-outCode").val());
	var subFundsName = $.trim($("#q-subFundsName").val());
    var fundCode = $.trim($("#q-fundCode").val());
    var feeName = $.trim($("#q-feeName").val());
    var expectPayDateBegin = $("#q-expectPayDate").getDateRangeValue()[0];
    var expectPayDateEnd = $("#q-expectPayDate").getDateRangeValue()[1];
    var bnsDateBegin = $("#q-bnsDate").getDateRangeValue()[0];
    var bnsDateEnd = $("#q-bnsDate").getDateRangeValue()[1];
    var isPay = $("#q-isPay").val();
    var feeType = $("#q-feeType").val();
    var deptId = $("#q-deptId").val();
	var mgrId = $("#q-mgrId").val();
	if(deptId == null){
		deptId = '';
	}
	if(mgrId == null){
		mgrId = '';	
	}
    
    var urlParam ='&sp[prjsName]='+prjsName
	+'&sp[outCode]='+outCode
	+'&sp[subFundsName]='+subFundsName
	+'&sp[fundCode]='+fundCode
	+'&sp[feeName]='+feeName
	+'&sp[expectPayDateBegin]='+expectPayDateBegin
	+'&sp[expectPayDateEnd]='+expectPayDateEnd
	+'&sp[bnsDateBegin]='+bnsDateBegin
	+'&sp[bnsDateEnd]='+bnsDateEnd
	+'&sp[feeType]='+feeType
	+'&sp[isPay]='+isPay
	+'&sp[deptId]='+deptId
	+'&sp[mgrId]='+mgrId;
	
	var actionUrl = PATH_PREFIX + "prdFeeYieldExportTo.do?"+urlParam;
	openDialog(actionUrl);
}

function showTitle(text, options, rData){
	var prjCode = rData["prjCode"];
	if(prjCode==null || prjCode == ''){
		return "";
	}
	return "<a href=javascript:showProductContent('"+ prjCode +"') class='showunderline'>"+text+"</a>";
}

//查看单产品详情信息
function showProductContent(prjCode){
	var actionUrl = prdPath + "singleProductOverview.do?prjcode="+prjCode;
	//openDialog(actionUrl);
	
	window.open(actionUrl);
}

//单个新增
function addFeeOrYield(subPrdCode,subFundsName){
	var actionUrl = PATH_PREFIX + 'addPrdFeeOrYieldView.do?subPrdCode='+subPrdCode+"&subFundsName="+subFundsName;
	window.open(actionUrl);  
}